package com.open.capacity.reimburse.controller;

import java.util.List;
import java.util.Map;

import com.open.capacity.commons.Result;
import com.open.capacity.reimburse.dto.ProjectBudgetDto;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.security.access.prepost.PreAuthorize;
import com.open.capacity.reimburse.entity.PbdBudgetAdjust1;
import com.open.capacity.reimburse.service.PbdBudgetAdjust1Service;

import com.open.capacity.commons.PageResult;

import javax.validation.Valid;

/**
 * 预算分配表
 *
 * @author
 * @email
 * @date 2021-06-29 10:26:52
 */
@RestController
@RequestMapping("pbdbudgetadjust1s")
@Api(tags = "预算分配")
public class PbdBudgetAdjust1Controller {

    @Autowired
    private PbdBudgetAdjust1Service pbdBudgetAdjust1Service;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @PreAuthorize("hasAnyAuthority('pbd_budget_adjust1:pbdbudgetadjust1:list')")
    public PageResult list(@RequestParam Map<String, Object> params) {
        PageResult pageResult = pbdBudgetAdjust1Service.pageAll(params);
        return pageResult;
    }

    /**
     * 分配图表
     */
    @RequestMapping("/getChart")
    public Result getChart(@RequestParam Map<String, Object> params) {
        Integer year = Integer.parseInt(params.get("year").toString());
        List<ProjectBudgetDto> result = pbdBudgetAdjust1Service.getChart(year);
        return Result.succeed(result);
    }

    /**
     * 查询单条记录
     */
    @RequestMapping("/findByProjectId")
    @PreAuthorize("hasAnyAuthority('pbd_budget_adjust1:pbdbudgetadjust1:list')")
    public Result findByProjectId(Integer year, String projectId) {
        return Result.succeed(pbdBudgetAdjust1Service.findByProjectId(year, projectId));
    }

    /**
     * 保存
     */
    @RequestMapping("/saveOrUpdate")
    @PreAuthorize("hasAnyAuthority('pbd_budget_adjust1:pbdbudgetadjust1:save')")
    public Result save(@RequestBody @Valid PbdBudgetAdjust1[] list) {
        pbdBudgetAdjust1Service.saveOrUpdate(list);
        return Result.succeed("保存成功");
    }


    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    @PreAuthorize("hasAnyAuthority('pbd_budget_adjust1:pbdbudgetadjust1:delete')")
    public Result delete(@PathVariable String id) {
        pbdBudgetAdjust1Service.delete(id);
        return Result.succeed("删除成功");
    }

}
